package com.liuya.safe.entitle.handler;

import com.liuya.base.BaseModel;
import com.liuya.safe.model.SafePrivilege;
import com.liuya.safe.entitle.service.PrivilegeManagerService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author liuya
 * @date 20160917
 */
@Component("nonRolePrivilegeTreeHandler")
public class NonRolePrivilegeTreeHandler extends PrivilegeTreeHandler {

    @Resource(name = "privilegeManagerService")
    public void setPrivilegeManagerService(PrivilegeManagerService privilegeManagerService){
        this.privilegeManagerService = privilegeManagerService;
    }

    public BaseModel getNode(HttpServletRequest req) {
        SafePrivilege priv = (SafePrivilege) super.getNode(req);
        priv.setType(1);

        return priv;
    }

    public Collection getAllNodes() {
        Collection pvlgs = privilegeManagerService.getAllNonRolePrivileges();
        List allPvlgs = new ArrayList(pvlgs.size() + 1);
        allPvlgs.addAll(pvlgs);
        return allPvlgs;
    }
}
